package Chinese.Education.Identify.service;

import Chinese.Education.Identify.mapper.StudentMapper;
import Chinese.Education.Identify.pojo.Student;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentService {

    @Resource
    private StudentMapper studentMapper;
    public Map<String, Object> selectStudent(int page, int limit, String name, String id) {
            int offset = (page - 1) * limit;
            List<Student> list = studentMapper.selectStudent( name, id,offset, limit);
            int count = studentMapper.selectCount();
            Map<String, Object> student = new HashMap<>();
            student.put("code", 0);
            student.put("msg", "");
            student.put("count", count);
            student.put("data", list);
            return student;
    }

    public Map<String, Object> insertStudent(Student student) {
            studentMapper.insertStudent(student);
            Map<String, Object> map = new HashMap<>();
            map.put("code",200);
            map.put("msg","新增成功");
            map.put("data",student);
            return map;

    }

    public Map<String, Object> deleteStudent(Student student) {
        studentMapper.deleteStudent(student);
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","删除成功");
        map.put("data",student);
        return map;

    }

    public Map<String, Object> updateStudent(Student student) {
        studentMapper.updateStudent(student);
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","修改成功");
        map.put("data",student);
        return map;

    }

}
